unit Canvas;

interface

uses
  Database, CProperties, RenameCanvas,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons, Menus, Db, DBTables;

type
  TFormCanvas = class(TForm)
    MainMenu: TMainMenu;
    MenuInvisible: TMenuItem;
    MenuEscape: TMenuItem;
    MenuPanic: TMenuItem;
    PopupOptions: TPopupMenu;
    PopupFontSize: TMenuItem;
    mf8: TMenuItem;
    mf10: TMenuItem;
    mf12: TMenuItem;
    mf14: TMenuItem;
    mf16: TMenuItem;
    mf18: TMenuItem;
    mf20: TMenuItem;
    PopupFontColor: TMenuItem;
    fc0: TMenuItem;
    fc1: TMenuItem;
    fc2: TMenuItem;
    fc3: TMenuItem;
    fc4: TMenuItem;
    fc5: TMenuItem;
    fc6: TMenuItem;
    fc7: TMenuItem;
    fc8: TMenuItem;
    fc9: TMenuItem;
    fc10: TMenuItem;
    fc11: TMenuItem;
    fc12: TMenuItem;
    fc13: TMenuItem;
    fc14: TMenuItem;
    fc15: TMenuItem;
    PopupColor: TMenuItem;
    mc16: TMenuItem;
    mc15: TMenuItem;
    mc14: TMenuItem;
    mc13: TMenuItem;
    mc12: TMenuItem;
    mc11: TMenuItem;
    mc10: TMenuItem;
    mc9: TMenuItem;
    mc8: TMenuItem;
    mc7: TMenuItem;
    mc6: TMenuItem;
    mc5: TMenuItem;
    mc4: TMenuItem;
    mc3: TMenuItem;
    mc2: TMenuItem;
    MenuColor1: TMenuItem;
    MenuTransparent: TMenuItem;
    N3: TMenuItem;
    PopupCloseEditor: TMenuItem;
    PopupLine1: TMenuItem;
    PopupOpenEditor: TMenuItem;
    N4: TMenuItem;
    MenuStayOnTop: TMenuItem;
    PopupProperties: TMenuItem;
    PopupAlignment: TMenuItem;
    fa0: TMenuItem;
    fa1: TMenuItem;
    fa2: TMenuItem;
    MenuCanvasColor: TMenuItem;
    cc15: TMenuItem;
    cc14: TMenuItem;
    cc13: TMenuItem;
    cc12: TMenuItem;
    cc11: TMenuItem;
    cc10: TMenuItem;
    cc9: TMenuItem;
    cc8: TMenuItem;
    cc7: TMenuItem;
    cc6: TMenuItem;
    cc5: TMenuItem;
    cc4: TMenuItem;
    cc3: TMenuItem;
    cc2: TMenuItem;
    cc1: TMenuItem;
    cc0: TMenuItem;
    CanvasProperties1: TMenuItem;
    MenuCanvasName: TMenuItem;
    Exit1: TMenuItem;
    N1: TMenuItem;
    moveup1: TMenuItem;
    movedown1: TMenuItem;
    moveright1: TMenuItem;
    moveleft1: TMenuItem;
    cu1: TMenuItem;
    cd1: TMenuItem;
    cr1: TMenuItem;
    cl1: TMenuItem;
    sl1: TMenuItem;
    sd1: TMenuItem;
    sr1: TMenuItem;
    sl2: TMenuItem;
    Help1: TMenuItem;
    Delete1: TMenuItem;
    PopupDeleteObject: TMenuItem;
    EditUnEdit1: TMenuItem;
    PopupBack: TMenuItem;
    PopupFront: TMenuItem;
    PopupLine2: TMenuItem;
    PopupSnap: TMenuItem;
    PanelBase: TPanel;
    PanelMain: TPanel;
    Grid: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Btn10: TBitBtn;
    Btn1: TBitBtn;
    Btn2: TBitBtn;
    Btn3: TBitBtn;
    Btn4: TBitBtn;
    Btn5: TBitBtn;
    Btn6: TBitBtn;
    Btn7: TBitBtn;
    Btn8: TBitBtn;
    Btn9: TBitBtn;
    sizeS: TPanel;
    Shape3: TShape;
    sizeN: TPanel;
    Shape1: TShape;
    sizeE: TPanel;
    Shape2: TShape;
    sizeW: TPanel;
    Shape4: TShape;
    HiddenButton: TButton;
    PanelTools: TPanel;
    LabelStats: TLabel;
    PanelRight: TPanel;
    BtnPointer: TSpeedButton;
    BtnLabel: TSpeedButton;
    BtnButton: TSpeedButton;
    Bevel1: TBevel;
    Bevel4: TBevel;
    Bevel2: TBevel;
    BtnVariables: TSpeedButton;
    BtnCloseEditor: TBitBtn;
    BtnHelp: TBitBtn;
    MenuHideTitlebar: TMenuItem;
    CloseCanvas1: TMenuItem;
    N2: TMenuItem;
    Label21: TLabel;
    Label22: TLabel;
    Label24: TLabel;
    Label23: TLabel;
    Label26: TLabel;
    Label25: TLabel;
    Label28: TLabel;
    Label27: TLabel;
    Label30: TLabel;
    Label29: TLabel;
    Properties1: TMenuItem;
    Timer: TTimer;
    N5: TMenuItem;
    MenuImport: TMenuItem;
    MenuExport: TMenuItem;
    DialogSave: TSaveDialog;
    DialogOpen: TOpenDialog;
    Import1: TMenuItem;
    Export: TMenuItem;
    ResetCanvas1: TMenuItem;
    N6: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure mf8Click(Sender: TObject);
    procedure fc0Click(Sender: TObject);
    procedure MenuColor1Click(Sender: TObject);
    procedure MenuEscapeClick(Sender: TObject);
    procedure sizeSMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure sizeSMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure sizeSMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BtnCloseEditorClick(Sender: TObject);
    procedure PopupCloseEditorClick(Sender: TObject);
    procedure PopupOpenEditorClick(Sender: TObject);
    procedure MenuStayOnTopClick(Sender: TObject);
    procedure PopupPropertiesClick(Sender: TObject);
    procedure Btn1Click(Sender: TObject);
    procedure GridMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure fa0Click(Sender: TObject);
    procedure PopupOptionsPopup(Sender: TObject);
    procedure cc0Click(Sender: TObject);
    procedure MenuCanvasNameClick(Sender: TObject);
    procedure MenuPanicClick(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure moveup1Click(Sender: TObject);
    procedure BtnHelpClick(Sender: TObject);
    procedure PanelMainMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Delete1Click(Sender: TObject);
    procedure EditUnEdit1Click(Sender: TObject);
    procedure PopupBackClick(Sender: TObject);
    procedure PopupSnapClick(Sender: TObject);
    procedure BtnVariablesMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BtnVariablesMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure MenuHideTitlebarClick(Sender: TObject);
    procedure Properties1Click(Sender: TObject);
    procedure TimerTimer(Sender: TObject);
    procedure MenuExportClick(Sender: TObject);
    procedure MenuImportClick(Sender: TObject);
    procedure ResetCanvas1Click(Sender: TObject);
  private
    { Private declarations }
    procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GETMINMAXINFO;
    procedure WMEnterSizeMove(var MSG: Tmessage);  message WM_ENTERSIZEMOVE;
    procedure WMExitSizeMove(var MSG: Tmessage);  message WM_EXITSIZEMOVE;
    function GetControl(ID: integer): TControl;
    procedure UpdateSelection;
    procedure DoProperties;
    procedure PlaceControl(id: integer; data: string);
    function FigureSave(id: integer): string;
    procedure PlaceLabel(x, y: integer);
    procedure PlaceButton(x, y: integer);
    procedure CheckRemaining;
    procedure UpdateTitlebar;
  public
    { Public declarations }
    gfile: string;
    procedure DrawGrid;
    procedure LoadOptions;
    procedure SaveOptions;
  end;

var
  FormCanvas: TFormCanvas;
  selx, sely, popitem, selected, sizing, gridD: integer;
  selecting, placing, didchange: boolean;
  trans: array [0..31] of boolean;
  caps: array [0..41] of string;

implementation

uses Main, DBClient, ScriptModule;

{$R *.DFM}

procedure TFormCanvas.FormCreate(Sender: TObject);
var i: integer;
begin
  gfile:='';
  didchange:=false;
  placing:=false;
  selecting:=false;
  sizing:=0;
  selx:=0; sely:=0;
  popitem:=0;
  selected:=0;
  gridD:=6;
  PanelTools.height:=0;
  LabelStats.caption:='';
  for i:=1 to 30 do trans[i]:=false;
  for i:=1 to 40 do caps[i]:='';
end;

procedure TFormCanvas.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if PanelTools.height > 0 then BtnCloseEditor.click;
  FormMain.UnloadScreen(10);
end;

procedure TFormCanvas.BtnHelpClick(Sender: TObject);
begin
  Datawell.Help('canvas');
end;

procedure TFormCanvas.WMGetMinMaxInfo(var MSG: Tmessage);
begin
  inherited;
  with PMinMaxInfo(MSG.lparam)^ do begin
    with ptMinTrackSize do begin
      X := 10;
      Y := 10;
    end;
    with ptMaxTrackSize do begin
      X := 9999;
      Y := 9999;
    end;
  end;
end;

procedure TFormCanvas.WMEnterSizeMove;
begin
  Grid.hide;
end;

procedure TFormCanvas.WMExitSizeMove;
begin
  if PanelTools.height = 0 then exit;
  Grid.show;
  DrawGrid;
end;

procedure TFormCanvas.LoadOptions;
begin
  PlaceControl(1,Datawell.TableOptions4.fieldbyname('S1').asstring);
  PlaceControl(2,Datawell.TableOptions4.fieldbyname('S2').asstring);
  PlaceControl(3,Datawell.TableOptions4.fieldbyname('S3').asstring);
  PlaceControl(4,Datawell.TableOptions4.fieldbyname('S4').asstring);
  PlaceControl(5,Datawell.TableOptions4.fieldbyname('S5').asstring);
  PlaceControl(6,Datawell.TableOptions4.fieldbyname('S6').asstring);
  PlaceControl(7,Datawell.TableOptions4.fieldbyname('S7').asstring);
  PlaceControl(8,Datawell.TableOptions4.fieldbyname('S8').asstring);
  PlaceControl(9,Datawell.TableOptions4.fieldbyname('S9').asstring);
  PlaceControl(10,Datawell.TableOptions4.fieldbyname('S10').asstring);
  PlaceControl(11,Datawell.TableOptions4.fieldbyname('S11').asstring);
  PlaceControl(12,Datawell.TableOptions4.fieldbyname('S12').asstring);
  PlaceControl(13,Datawell.TableOptions4.fieldbyname('S13').asstring);
  PlaceControl(14,Datawell.TableOptions4.fieldbyname('S14').asstring);
  PlaceControl(15,Datawell.TableOptions4.fieldbyname('S15').asstring);
  PlaceControl(16,Datawell.TableOptions4.fieldbyname('S16').asstring);
  PlaceControl(17,Datawell.TableOptions4.fieldbyname('S17').asstring);
  PlaceControl(18,Datawell.TableOptions4.fieldbyname('S18').asstring);
  PlaceControl(19,Datawell.TableOptions4.fieldbyname('S19').asstring);
  PlaceControl(20,Datawell.TableOptions4.fieldbyname('S20').asstring);
  PlaceControl(101,Datawell.TableOptions4.fieldbyname('S21').asstring);
  PlaceControl(102,Datawell.TableOptions4.fieldbyname('S22').asstring);
  PlaceControl(103,Datawell.TableOptions4.fieldbyname('S23').asstring);
  PlaceControl(104,Datawell.TableOptions4.fieldbyname('S24').asstring);
  PlaceControl(105,Datawell.TableOptions4.fieldbyname('S25').asstring);
  PlaceControl(106,Datawell.TableOptions4.fieldbyname('S26').asstring);
  PlaceControl(107,Datawell.TableOptions4.fieldbyname('S27').asstring);
  PlaceControl(108,Datawell.TableOptions4.fieldbyname('S28').asstring);
  PlaceControl(109,Datawell.TableOptions4.fieldbyname('S29').asstring);
  PlaceControl(110,Datawell.TableOptions4.fieldbyname('S30').asstring);
  PlaceControl(21,Datawell.TableOptions4.fieldbyname('S31').asstring);
  PlaceControl(22,Datawell.TableOptions4.fieldbyname('S32').asstring);
  PlaceControl(23,Datawell.TableOptions4.fieldbyname('S33').asstring);
  PlaceControl(24,Datawell.TableOptions4.fieldbyname('S34').asstring);
  PlaceControl(25,Datawell.TableOptions4.fieldbyname('S35').asstring);
  PlaceControl(26,Datawell.TableOptions4.fieldbyname('S36').asstring);
  PlaceControl(27,Datawell.TableOptions4.fieldbyname('S37').asstring);
  PlaceControl(28,Datawell.TableOptions4.fieldbyname('S38').asstring);
  PlaceControl(29,Datawell.TableOptions4.fieldbyname('S39').asstring);
  PlaceControl(30,Datawell.TableOptions4.fieldbyname('S40').asstring);
  UpdateSelection;
  CheckRemaining;
  didchange:=false;
end;

procedure TFormCanvas.SaveOptions;
begin
  Datawell.TableOptions4.edit;
  Datawell.TableOptions4.fieldbyname('S1').asstring:=FigureSave(1);
  Datawell.TableOptions4.fieldbyname('S2').asstring:=FigureSave(2);
  Datawell.TableOptions4.fieldbyname('S3').asstring:=FigureSave(3);
  Datawell.TableOptions4.fieldbyname('S4').asstring:=FigureSave(4);
  Datawell.TableOptions4.fieldbyname('S5').asstring:=FigureSave(5);
  Datawell.TableOptions4.fieldbyname('S6').asstring:=FigureSave(6);
  Datawell.TableOptions4.fieldbyname('S7').asstring:=FigureSave(7);
  Datawell.TableOptions4.fieldbyname('S8').asstring:=FigureSave(8);
  Datawell.TableOptions4.fieldbyname('S9').asstring:=FigureSave(9);
  Datawell.TableOptions4.fieldbyname('S10').asstring:=FigureSave(10);
  Datawell.TableOptions4.fieldbyname('S11').asstring:=FigureSave(11);
  Datawell.TableOptions4.fieldbyname('S12').asstring:=FigureSave(12);
  Datawell.TableOptions4.fieldbyname('S13').asstring:=FigureSave(13);
  Datawell.TableOptions4.fieldbyname('S14').asstring:=FigureSave(14);
  Datawell.TableOptions4.fieldbyname('S15').asstring:=FigureSave(15);
  Datawell.TableOptions4.fieldbyname('S16').asstring:=FigureSave(16);
  Datawell.TableOptions4.fieldbyname('S17').asstring:=FigureSave(17);
  Datawell.TableOptions4.fieldbyname('S18').asstring:=FigureSave(18);
  Datawell.TableOptions4.fieldbyname('S19').asstring:=FigureSave(19);
  Datawell.TableOptions4.fieldbyname('S20').asstring:=FigureSave(20);
  Datawell.TableOptions4.fieldbyname('S21').asstring:=FigureSave(101);
  Datawell.TableOptions4.fieldbyname('S22').asstring:=FigureSave(102);
  Datawell.TableOptions4.fieldbyname('S23').asstring:=FigureSave(103);
  Datawell.TableOptions4.fieldbyname('S24').asstring:=FigureSave(104);
  Datawell.TableOptions4.fieldbyname('S25').asstring:=FigureSave(105);
  Datawell.TableOptions4.fieldbyname('S26').asstring:=FigureSave(106);
  Datawell.TableOptions4.fieldbyname('S27').asstring:=FigureSave(107);
  Datawell.TableOptions4.fieldbyname('S28').asstring:=FigureSave(108);
  Datawell.TableOptions4.fieldbyname('S29').asstring:=FigureSave(109);
  Datawell.TableOptions4.fieldbyname('S30').asstring:=FigureSave(110);
  Datawell.TableOptions4.fieldbyname('S31').asstring:=FigureSave(21);
  Datawell.TableOptions4.fieldbyname('S32').asstring:=FigureSave(22);
  Datawell.TableOptions4.fieldbyname('S33').asstring:=FigureSave(23);
  Datawell.TableOptions4.fieldbyname('S34').asstring:=FigureSave(24);
  Datawell.TableOptions4.fieldbyname('S35').asstring:=FigureSave(25);
  Datawell.TableOptions4.fieldbyname('S36').asstring:=FigureSave(26);
  Datawell.TableOptions4.fieldbyname('S37').asstring:=FigureSave(27);
  Datawell.TableOptions4.fieldbyname('S38').asstring:=FigureSave(28);
  Datawell.TableOptions4.fieldbyname('S39').asstring:=FigureSave(29);
  Datawell.TableOptions4.fieldbyname('S40').asstring:=FigureSave(30);
  Datawell.TableOptions4.post;
end;

procedure TFormCanvas.PlaceControl(id: integer; data: string);
var
  lab: TLabel;
  but: TBitBtn;
  p, t, l, h, w, col, fsize, fcol, fal: integer;
  work, hin, cap: string;
  vis, trans, didfind: boolean;
  table: TClientDataset;
begin
  work:=copy(data,1,3);
  if work <> '#K%' then exit;
  delete(data,1,3);
  //visible
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  vis:=(work = '1');
  //hint
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  hin:=work;
  //top, left, height, width
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  t:=Datawell.toint(work);
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  l:=Datawell.toint(work);
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  h:=Datawell.toint(work);
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  w:=Datawell.toint(work);
  //caption
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  cap:=work;
  //color
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  if work = '-1' then col:=-1
  else col:=Datawell.FigureColor(Datawell.toint(work));
  //font size
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  fsize:=Datawell.toint(work);
  //font color
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  fcol:=Datawell.FigureColor(Datawell.toint(work));
  //font alignment
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  fal:=Datawell.toint(work);
  //transparent
  p:=pos('|',data);
  work:=copy(data,1,p-1); delete(data,1,p);
  trans:=(work = '1');
  if id <= 100 then begin
    lab:=TLabel(GetControl(id));
    //Check to see if hint is actually a variable
    if hin <> '' then begin
      didfind:=false;
      if hin = '@HP' then didfind:=true
      else if hin = '@MAXHP' then didfind:=true
      else if hin = '@SP' then didfind:=true
      else if hin = '@MAXSP' then didfind:=true
      else if hin = '@GP1' then didfind:=true
      else if hin = '@MAXGP1' then didfind:=true
      else if hin = '@GP2' then didfind:=true
      else if hin = '@MAXGP2' then didfind:=true
      else if hin = '@ENEMY' then didfind:=true
      else if hin = '@ENAME' then didfind:=true
      else if hin = '@GLINE1' then didfind:=true
      else if hin = '@GLINE2' then didfind:=true
      else if hin = '@CAPTION' then didfind:=true
      else if hin = '@AA' then didfind:=true
      else if hin = '@BB' then didfind:=true
      else if hin = '@CC' then didfind:=true
      else if hin = '@DD' then didfind:=true
      else if hin = '@EE' then didfind:=true
      else if hin = '@FF' then didfind:=true;
      if not didfind then begin
        table:=TClientDataset.create(self);
        with table do begin
          CloneCursor(Datawell.TableVariables, false);
          filtered := true;
          active:=true;
          first;
          while not EOF do begin
            if '@'+fieldbyname('FVariable').asstring = hin then begin
              didfind:=true;
              break;
            end;
            next;
          end;
        end;
        table.free;
      end;
      if not didfind then begin
        hin:='';
        cap:='<nil>';
      end;
    end;
    lab.hint:=hin;
    lab.top:=t;
    lab.left:=l;
    lab.height:=h;
    lab.width:=w;
    lab.caption:=cap;
    if col = -1 then lab.transparent:=true else lab.color:=col;
    lab.font.size:=fsize;
    lab.font.color:=fcol;
    case fal of
      0: lab.alignment:=taleftjustify;
      1: lab.alignment:=tacenter;
      2: lab.alignment:=tarightjustify;
    end;
    lab.visible:=vis;
    lab.transparent:=trans;
  end
  else begin
    but:=TBitBtn(GetControl(id));
    but.hint:=hin;
    but.top:=t;
    but.left:=l;
    but.height:=h;
    but.width:=w;
    but.caption:=cap;
    but.font.size:=fsize;
    but.font.color:=fcol;
    but.visible:=vis;
  end;
end;

function TFormCanvas.FigureSave(id: integer): string;
var ob: TControl;
begin
  result:='';
  ob:=GetControl(id);
  //visible
  if ob.visible then result:=result+'1|' else result:=result+'0|';
  //hint
  result:=result+ob.hint+'|';
  //top, left, height, width
  result:=result+inttostr(ob.top)+'|';
  result:=result+inttostr(ob.left)+'|';
  result:=result+inttostr(ob.height)+'|';
  result:=result+inttostr(ob.width)+'|';
  if id <= 100 then begin //Label
    //caption
    result:=result+TButton(ob).caption+'|';
    //color
    if TLabel(ob).transparent then result:=result+'-1|'
    else result:=result+inttostr(Datawell.ColorFigure(TLabel(ob).color))+'|';
    //font size
    result:=result+inttostr(TLabel(ob).font.size)+'|';
    //font color
    result:=result+inttostr(Datawell.ColorFigure(TLabel(ob).font.color))+'|';
    //font alignment
    if TLabel(ob).alignment = taleftjustify then result:=result+'0|'
    else if TLabel(ob).alignment = tacenter then result:=result+'1|'
    else result:=result+'2|';
    //transparent
    if TLabel(ob).transparent then result:=result+'1|' else  result:=result+'0|';
  end
  else begin //Button
    //caption
    result:=result+TBitBtn(ob).caption+'|';
    //color (nil)
    result:=result+'|';
    //font size
    result:=result+inttostr(TBitBtn(ob).font.size)+'|';
    //font color
    result:=result+inttostr(Datawell.ColorFigure(TBitBtn(ob).font.color))+'|';
    //font alignment (nil)
    result:=result+'|';
    //transparent (nil)
    result:=result+'0|';
  end;
  result:='#K%'+result;
end;

procedure TFormCanvas.Label1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  ob: TObject;
  fontsize, fontcolor: integer;
begin
  popitem:=TComponent(sender).tag;
  if PanelTools.height = 0 then begin
    if button = mbright then begin
      PopupProperties.visible:=true;
      PopupLine1.visible:=true;
      PopupLine2.visible:=false;
    end;
    exit;
  end;
  if button = mbright then begin
    PopupProperties.visible:=true;
    PopupLine1.visible:=true;
    PopupLine2.visible:=true;
    PopupFontSize.visible:=true;
    PopupFontColor.visible:=true;
    PopupColor.visible:=false;
    PopupAlignment.visible:=false;
    PopupDeleteObject.visible:=true;
//    PopupBack.visible:=true;
//    PopupFront.visible:=true;
    MenuTransparent.checked:=false;
    MenuColor1.checked:=false;
    mc2.checked:=false;
    mc3.checked:=false;
    mc4.checked:=false;
    mc5.checked:=false;
    mc6.checked:=false;
    mc7.checked:=false;
    mc8.checked:=false;
    mc9.checked:=false;
    mc10.checked:=false;
    mc11.checked:=false;
    mc12.checked:=false;
    mc13.checked:=false;
    mc14.checked:=false;
    mc15.checked:=false;
    mc16.checked:=false;
    mf8.checked:=false;
    mf10.checked:=false;
    mf12.checked:=false;
    mf14.checked:=false;
    mf16.checked:=false;
    mf18.checked:=false;
    mf20.checked:=false;
    fc0.checked:=false;
    fc1.checked:=false;
    fc2.checked:=false;
    fc3.checked:=false;
    fc4.checked:=false;
    fc5.checked:=false;
    fc6.checked:=false;
    fc7.checked:=false;
    fc8.checked:=false;
    fc9.checked:=false;
    fc10.checked:=false;
    fc11.checked:=false;
    fc12.checked:=false;
    fc13.checked:=false;
    fc14.checked:=false;
    fc15.checked:=false;
    fa0.checked:=false;
    fa1.checked:=false;
    fa2.checked:=false;
    if popitem <= 100 then begin
      PopupColor.visible:=true;
      PopupAlignment.visible:=true;
      ob:=GetControl(popitem);
      fontsize:=TButton(ob).font.size;
      fontcolor:=TButton(ob).font.color;
      case TLabel(ob).alignment of
        taLeftJustify: fa0.checked:=true;
        taCenter: fa1.checked:=true;
        taRightJustify: fa2.checked:=true;
      end;
      if trans[popitem] then MenuTransparent.checked:=true
      else begin
        case TLabel(ob).color of
          clblack: MenuColor1.checked:=true;
          clmaroon: mc2.checked:=true;
          clgreen: mc3.checked:=true;
          clolive: mc4.checked:=true;
          clnavy: mc5.checked:=true;
          clpurple: mc6.checked:=true;
          clteal: mc7.checked:=true;
          clsilver: mc8.checked:=true;
          clgray: mc9.checked:=true;
          clred: mc10.checked:=true;
          cllime: mc11.checked:=true;
          clyellow: mc12.checked:=true;
          clblue: mc13.checked:=true;
          clfuchsia: mc14.checked:=true;
          claqua: mc15.checked:=true;
          clwhite: mc16.checked:=true;
        end;
      end;
    end
    else begin
      ob:=GetControl(popitem);
      fontsize:=TBitBtn(ob).font.size;
      fontcolor:=TBitBtn(ob).font.color;
    end;
    case fontsize of
      8: mf8.checked:=true;
      10: mf10.checked:=true;
      12: mf12.checked:=true;
      14: mf14.checked:=true;
      16: mf16.checked:=true;
      18: mf18.checked:=true;
      20: mf20.checked:=true;
    end;
    case fontcolor of
      clblack: fc0.checked:=true;
      clmaroon: fc1.checked:=true;
      clgreen: fc2.checked:=true;
      clolive: fc3.checked:=true;
      clnavy: fc4.checked:=true;
      clpurple: fc5.checked:=true;
      clteal: fc6.checked:=true;
      clsilver: fc7.checked:=true;
      clgray: fc8.checked:=true;
      clred: fc9.checked:=true;
      cllime: fc10.checked:=true;
      clyellow: fc11.checked:=true;
      clblue: fc12.checked:=true;
      clfuchsia: fc13.checked:=true;
      claqua: fc14.checked:=true;
      clwhite: fc15.checked:=true;
    end;
  end
  else if button = mbleft then selecting:=true;
  selected:=TComponent(sender).tag;
  UpdateSelection;
  selx:=x; sely:=y;
end;

procedure TFormCanvas.Label1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  selecting:=false;
  selx:=0; sely:=0;
end;

procedure TFormCanvas.Label1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var newx, newy, w, h: integer;
begin
  if not selecting then exit;
  w:=TControl(sender).width;
  h:=TControl(sender).height;
  newx:=TControl(sender).left+x-selx;
  newy:=TControl(sender).top+y-sely;
  if PopupSnap.checked then begin
    newx:=(newx div gridD) * gridD;
    newy:=(newy div gridD) * gridD;
  end;  
  if newx < 0 then newx:=0;
  if newx > PanelMain.width-w then newx:=PanelMain.width-w;
  if newy < 0 then newy:=0;
  if newy > PanelMain.height-h then newy:=PanelMain.height-h;
  TControl(sender).left:=newx;
  TControl(sender).top:=newy;
  UpdateSelection;
  didchange:=true;
end;

function TFormCanvas.GetControl(ID: integer): TControl;
begin
  if ID < 1 then abort;
  case ID of
    1: result:=label1;
    2: result:=label2;
    3: result:=label3;
    4: result:=label4;
    5: result:=label5;
    6: result:=label6;
    7: result:=label7;
    8: result:=label8;
    9: result:=label9;
    10: result:=label10;
    11: result:=label11;
    12: result:=label12;
    13: result:=label13;
    14: result:=label14;
    15: result:=label15;
    16: result:=label16;
    17: result:=label17;
    18: result:=label18;
    19: result:=label19;
    20: result:=label20;
    21: result:=label21;
    22: result:=label22;
    23: result:=label23;
    24: result:=label24;
    25: result:=label25;
    26: result:=label26;
    27: result:=label27;
    28: result:=label28;
    29: result:=label29;
    30: result:=label30;
    101: result:=Btn1;
    102: result:=Btn2;
    103: result:=Btn3;
    104: result:=Btn4;
    105: result:=Btn5;
    106: result:=Btn6;
    107: result:=Btn7;
    108: result:=Btn8;
    109: result:=Btn9;
    110: result:=Btn10;
    else raise Exception.CreateFmt('TFormCanvas.GetControl: Invalid control ID: %d', [ID]);
  end;
end;

procedure TFormCanvas.mf8Click(Sender: TObject);
var ob: TControl;
begin
  ob:=GetControl(popitem);
  if popitem <= 100 then TButton(ob).font.size:=TComponent(sender).tag
  else TBitBtn(ob).font.size:=TComponent(sender).tag;
  didchange:=true;
end;

procedure TFormCanvas.fc0Click(Sender: TObject);
var ob: TControl;
begin
  ob:=GetControl(popitem);
  if popitem <= 100 then TButton(ob).font.color:=Datawell.FigureColor(TComponent(sender).tag)
  else TBitBtn(ob).font.color:=Datawell.FigureColor(TComponent(sender).tag);
  didchange:=true;
end;

procedure TFormCanvas.MenuColor1Click(Sender: TObject);
var ob: TControl;
begin
  if popitem > 100 then exit;
  ob:=GetControl(popitem);
  didchange:=true;
  if TComponent(sender).tag = -1 then begin
    trans[popitem]:=true;
    TLabel(ob).color:=clgray;
    exit;
  end;
  trans[popitem]:=false;
  TLabel(ob).color:=Datawell.FigureColor(TComponent(sender).tag);
end;

procedure TFormCanvas.MenuEscapeClick(Sender: TObject);
begin
  if selected > 0 then begin
    selected:=0;
    UpdateSelection;
    exit;
  end;
  FormMain.show;
end;

procedure TFormCanvas.UpdateSelection;
var ob: TControl;
begin
  if selected < 1 then begin
    sizeN.hide;
    sizeS.hide;
    sizeE.hide;
    sizeW.hide;
    LabelStats.caption:='';
  end
  else begin
    ob:=GetControl(selected);
    sizeN.top:=TControl(ob).top-2;
    sizeN.left:=TControl(ob).left+(TControl(ob).width div 2)-3;
    sizeN.show;
    sizeS.top:=TControl(ob).top+TControl(ob).height-4;
    sizeS.left:=TControl(ob).left+(TControl(ob).width div 2)-3;
    sizeS.show;
    sizeE.top:=TControl(ob).top+(TControl(ob).height div 2)-3;
    sizeE.left:=TControl(ob).left+TControl(ob).width-4;
    sizeE.show;
    sizeW.top:=TControl(ob).top+(TControl(ob).height div 2)-3;
    sizeW.left:=TControl(ob).left-2;
    sizeW.show;
    LabelStats.caption:=
      ' ('+inttostr(TControl(ob).left)+'x,'+
      inttostr(TControl(ob).top)+'y)  '+
      inttostr(TControl(ob).height)+'h X '+inttostr(TControl(ob).width)+'w';
  end;
end;

procedure TFormCanvas.sizeSMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  sizing:=TComponent(sender).tag;
end;

procedure TFormCanvas.sizeSMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  sizing:=0;
end;

procedure TFormCanvas.sizeSMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  ob: TControl;
  newh, neww, newt, newl, p: integer;
begin
  if sizing < 1 then exit;
  ob:=GetControl(selected);
  case TComponent(sender).tag of
    8: begin
         if sizing <> 8 then exit;
         newt:=ob.top+y;
         if PopupSnap.checked then newt:=(newt div gridD) * gridD;
         if newt < 0 then newt:=0;
         newh:=ob.height+ob.top-newt;
         if newh < 8 then begin
           newh:=8;
           newt:=ob.top;
         end;
         ob.height:=newh;
         ob.top:=newt;
         UpdateSelection;
       end;
    2: begin
         if sizing <> 2 then exit;
         newh:=ob.height+y;
         if PopupSnap.checked then begin
           p:=ob.top+newh;
           p:=(p div gridD) * gridD;
           newh:=p-ob.top;
         end;
         if newh < 8 then newh:=8;
         if ob.top > PanelMain.height-newh then
           newh:=PanelMain.height-ob.top;
         ob.height:=newh;
         UpdateSelection;
       end;
    6: begin
         if sizing <> 6 then exit;
         neww:=ob.width+x;
         if PopupSnap.checked then begin
           p:=ob.left+neww;
           p:=(p div gridD) * gridD;
           neww:=p-ob.left;
         end;  
         if neww < 8 then neww:=8;
         if ob.left > PanelMain.width-neww then
           neww:=PanelMain.width-ob.left;
         ob.width:=neww;
         UpdateSelection;
       end;
    4: begin
         if sizing <> 4 then exit;
         newl:=ob.left+x;
         if PopupSnap.checked then newl:=(newl div gridD) * gridD;
         if newl < 0 then newl:=0;
         neww:=ob.width+ob.left-newl;
         if neww < 8 then begin
           neww:=8;
           newl:=ob.left;
         end;
         ob.width:=neww;
         ob.left:=newl;
         UpdateSelection;
       end;
  end;
end;

procedure TFormCanvas.DrawGrid;
var w, h, i, j: integer;
begin
  w:=grid.width;
  h:=grid.height;
  with grid.canvas do begin
    pen.width:=1;
    brush.color:=PanelMain.color;
    if (brush.color = clblack) or (brush.color = clnavy) then pen.color:=clsilver
    else pen.color:=clblack;
    polygon([point(0,0),point(w-1,0),point(w-1,h-1),point(0,h-1)]);
    i:=gridD;
    while i < w do begin
      j:=gridD;
      while j < h do begin
        pixels[i,j]:=pen.color;
        inc(j,gridD);
      end;
      inc(i,gridD);
    end;
  end;
end;

procedure TFormCanvas.PopupOpenEditorClick(Sender: TObject);
begin
  PanelTools.height:=24;
  if borderstyle = bsnone then begin
    height:=height+22;
    width:=width+8;
  end;
  height:=height+PanelTools.height+2;
  Grid.show;
  DrawGrid;
  PopupOpenEditor.visible:=false;
  PopupCloseEditor.visible:=true;
  PopupSnap.visible:=true;
  PopupLine1.visible:=true;
  borderstyle:=bssizetoolwin;
  if Label1.transparent then begin
    Label1.transparent:=false;
    Label1.color:=clgray;
    trans[1]:=true;
  end;
  if Label2.transparent then begin
    Label2.transparent:=false;
    Label2.color:=clgray;
    trans[2]:=true;
  end;
  if Label3.transparent then begin
    Label3.transparent:=false;
    Label3.color:=clgray;
    trans[3]:=true;
  end;
  if Label4.transparent then begin
    Label4.transparent:=false;
    Label4.color:=clgray;
    trans[4]:=true;
  end;
  if Label5.transparent then begin
    Label5.transparent:=false;
    Label5.color:=clgray;
    trans[5]:=true;
  end;
  if Label6.transparent then begin
    Label6.transparent:=false;
    Label6.color:=clgray;
    trans[6]:=true;
  end;
  if Label7.transparent then begin
    Label7.transparent:=false;
    Label7.color:=clgray;
    trans[7]:=true;
  end;
  if Label8.transparent then begin
    Label8.transparent:=false;
    Label8.color:=clgray;
    trans[8]:=true;
  end;
  if Label9.transparent then begin
    Label9.transparent:=false;
    Label9.color:=clgray;
    trans[9]:=true;
  end;
  if Label10.transparent then begin
    Label10.transparent:=false;
    Label10.color:=clgray;
    trans[10]:=true;
  end;
  if Label11.transparent then begin
    Label11.transparent:=false;
    Label11.color:=clgray;
    trans[11]:=true;
  end;
  if Label12.transparent then begin
    Label12.transparent:=false;
    Label12.color:=clgray;
    trans[12]:=true;
  end;
  if Label13.transparent then begin
    Label13.transparent:=false;
    Label13.color:=clgray;
    trans[13]:=true;
  end;
  if Label14.transparent then begin
    Label14.transparent:=false;
    Label14.color:=clgray;
    trans[14]:=true;
  end;
  if Label15.transparent then begin
    Label15.transparent:=false;
    Label15.color:=clgray;
    trans[15]:=true;
  end;
  if Label16.transparent then begin
    Label16.transparent:=false;
    Label16.color:=clgray;
    trans[16]:=true;
  end;
  if Label17.transparent then begin
    Label17.transparent:=false;
    Label17.color:=clgray;
    trans[17]:=true;
  end;
  if Label18.transparent then begin
    Label18.transparent:=false;
    Label18.color:=clgray;
    trans[18]:=true;
  end;
  if Label19.transparent then begin
    Label19.transparent:=false;
    Label19.color:=clgray;
    trans[19]:=true;
  end;
  if Label20.transparent then begin
    Label20.transparent:=false;
    Label20.color:=clgray;
    trans[20]:=true;
  end;
  if Label21.transparent then begin
    Label21.transparent:=false;
    Label21.color:=clgray;
    trans[21]:=true;
  end;
  if Label22.transparent then begin
    Label22.transparent:=false;
    Label22.color:=clgray;
    trans[22]:=true;
  end;
  if Label23.transparent then begin
    Label23.transparent:=false;
    Label23.color:=clgray;
    trans[23]:=true;
  end;
  if Label24.transparent then begin
    Label24.transparent:=false;
    Label24.color:=clgray;
    trans[24]:=true;
  end;
  if Label25.transparent then begin
    Label25.transparent:=false;
    Label25.color:=clgray;
    trans[25]:=true;
  end;
  if Label26.transparent then begin
    Label26.transparent:=false;
    Label26.color:=clgray;
    trans[26]:=true;
  end;
  if Label27.transparent then begin
    Label27.transparent:=false;
    Label27.color:=clgray;
    trans[27]:=true;
  end;
  if Label28.transparent then begin
    Label28.transparent:=false;
    Label28.color:=clgray;
    trans[28]:=true;
  end;
  if Label29.transparent then begin
    Label29.transparent:=false;
    Label29.color:=clgray;
    trans[29]:=true;
  end;
  if Label30.transparent then begin
    Label30.transparent:=false;
    Label30.color:=clgray;
    trans[30]:=true;
  end;
end;

procedure TFormCanvas.BtnCloseEditorClick(Sender: TObject);
var i: integer;
begin
  if PanelTools.height = 0 then exit;
  height:=height-PanelTools.height-2;
  PanelTools.height:=0;
  selected:=0;
  UpdateSelection;
  Grid.hide;
  PopupCloseEditor.visible:=false;
  PopupOpenEditor.visible:=true;
  PopupSnap.visible:=false;
  PopupColor.visible:=false;
  PopupFontSize.visible:=false;
  PopupFontColor.visible:=false;
  PopupAlignment.visible:=false;
  PopupDeleteObject.visible:=false;
  PopupBack.visible:=false;
  PopupFront.visible:=false;
  if not MenuHideTitlebar.checked then begin
    height:=height-22;
    width:=width-8;
  end;
  UpdateTitlebar;
  for i:=1 to 30 do begin
    if trans[i] then begin
      case i of
        1: Label1.transparent:=true;
        2: Label2.transparent:=true;
        3: Label3.transparent:=true;
        4: Label4.transparent:=true;
        5: Label5.transparent:=true;
        6: Label6.transparent:=true;
        7: Label7.transparent:=true;
        8: Label8.transparent:=true;
        9: Label9.transparent:=true;
        10: Label10.transparent:=true;
        11: Label11.transparent:=true;
        12: Label12.transparent:=true;
        13: Label13.transparent:=true;
        14: Label14.transparent:=true;
        15: Label15.transparent:=true;
        16: Label16.transparent:=true;
        17: Label17.transparent:=true;
        18: Label18.transparent:=true;
        19: Label19.transparent:=true;
        20: Label20.transparent:=true;
        21: Label21.transparent:=true;
        22: Label22.transparent:=true;
        23: Label23.transparent:=true;
        24: Label24.transparent:=true;
        25: Label25.transparent:=true;
        26: Label26.transparent:=true;
        27: Label27.transparent:=true;
        28: Label28.transparent:=true;
        29: Label29.transparent:=true;
        30: Label30.transparent:=true;
      end;
    end;
    trans[i]:=false;
  end;
end;

procedure TFormCanvas.PopupCloseEditorClick(Sender: TObject);
begin
  BtnCloseEditor.click;
end;

procedure TFormCanvas.MenuStayOnTopClick(Sender: TObject);
begin
  MenuStayOnTop.checked:=not MenuStayOnTop.checked;
  if MenuStayOnTop.checked = true then formstyle:=fsstayontop
  else formstyle:=fsnormal;
  didchange:=true;
end;

procedure TFormCanvas.Btn1Click(Sender: TObject);
var com: string;
begin
  HiddenButton.setfocus;
  if PanelTools.Height > 0 then exit;
  com:=TBitBtn(sender).hint;
  if com = '' then exit;
  FormMain.ExternalParse(com,1);
  FormMain.show;
end;

procedure TFormCanvas.GridMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbright then begin
    popitem:=0;
    PopupProperties.visible:=false;
    PopupLine1.visible:=false;
    PopupLine2.visible:=false;
    PopupColor.visible:=false;
    PopupFontSize.visible:=false;
    PopupFontColor.visible:=false;
    PopupAlignment.visible:=false;
    PopupDeleteObject.visible:=false;
    PopupBack.visible:=false;
    PopupFront.visible:=false;
    exit;
  end;
  if BtnPointer.down then begin
    selected:=0;
    UpdateSelection;
    exit;
  end;
  if BtnLabel.down then PlaceLabel(x,y) else PlaceButton(x,y);
  UpdateSelection;
  BtnPointer.down:=true;
  CheckRemaining;
  placing:=true;
  DoProperties;
  placing:=false;
end;

procedure TFormCanvas.fa0Click(Sender: TObject);
var ob: TControl;
begin
  if popitem > 100 then exit;
  ob:=GetControl(popitem);
  case TComponent(sender).tag of
    0: TLabel(ob).alignment:=taleftjustify;
    1: TLabel(ob).alignment:=tacenter;
    2: TLabel(ob).alignment:=tarightjustify;
  end;
  didchange:=true;
end;

procedure TFormCanvas.PopupOptionsPopup(Sender: TObject);
begin
  cc0.checked:=false;
  cc1.checked:=false;
  cc2.checked:=false;
  cc3.checked:=false;
  cc4.checked:=false;
  cc5.checked:=false;
  cc6.checked:=false;
  cc7.checked:=false;
  cc8.checked:=false;
  cc9.checked:=false;
  cc10.checked:=false;
  cc11.checked:=false;
  cc12.checked:=false;
  cc13.checked:=false;
  cc14.checked:=false;
  cc15.checked:=false;
  case PanelMain.color of
    clblack: cc0.checked:=true;
    clmaroon: cc1.checked:=true;
    clgreen: cc2.checked:=true;
    clolive: cc3.checked:=true;
    clnavy: cc4.checked:=true;
    clpurple: cc5.checked:=true;
    clteal: cc6.checked:=true;
    clsilver: cc7.checked:=true;
    clgray: cc8.checked:=true;
    clred: cc9.checked:=true;
    cllime: cc10.checked:=true;
    clyellow: cc11.checked:=true;
    clblue: cc12.checked:=true;
    clfuchsia: cc13.checked:=true;
    claqua: cc14.checked:=true;
    clwhite: cc15.checked:=true;
  end;
end;

procedure TFormCanvas.cc0Click(Sender: TObject);
begin
  PanelMain.color:=Datawell.FigureColor(TComponent(sender).tag);
  if PanelTools.height > 0 then DrawGrid;
  didchange:=true;
end;
                                      
procedure TFormCanvas.MenuCanvasNameClick(Sender: TObject);
var
  form: TFormRenameCanvas;
  cap: string;
begin
  form:=TFormRenameCanvas.create(self);
  form.EditCaption.text:=Datawell.TableOptions3.fieldbyname('S31').asstring;
  form.showmodal;
  cap:=form.cap;
  form.free;
  if cap = '<nIl>' then exit;
  Datawell.TableOptions3.edit;
  Datawell.TableOptions3.fieldbyname('S31').asstring:=cap;
  Datawell.TableOptions3.post;
  didchange:=true;
  FormMain.UpdateWindowCaptions;
end;

procedure TFormCanvas.PopupPropertiesClick(Sender: TObject);
begin
  DoProperties;
end;

procedure TFormCanvas.DoProperties;
var
  form: TFormCProperties;
  lab, val, kind: string;
  variable: boolean;
  id: integer;
  ob: TControl;
begin
  id:=selected;
  if id < 1 then id:=popitem;
  if id < 1 then exit;
  ob:=GetControl(id);
  form:=TFormCProperties.create(self);
  if id > 100 then begin
    form.IsButton;
    form.EditButtonLabel.text:=TBitBtn(ob).caption;
    form.EditCommand.text:=TBitBtn(ob).hint;
  end
  else begin
    if TLabel(ob).hint <> '' then form.EditVariable.text:=TLabel(ob).hint
    else form.EditText.text:=TLabel(ob).caption;
  end;
  if placing then begin
    form.BtnSave.left:=form.BtnCancel.left;
    form.BtnCancel.hide;
  end;
  form.showmodal;
  kind:=form.kind;
  lab:=form.lab;
  val:=form.val;
  if form.RBVariable.checked then variable:=true else variable:=false;
  form.free;
  //Clear any selection
  Timer.enabled:=true;
  if kind = '' then exit;
  didchange:=true;
  if kind = 'label' then begin
    if not variable then begin
      TButton(ob).caption:=lab;
      TButton(ob).hint:='';
    end
    else begin
      TLabel(ob).hint:=val;
      TLabel(ob).caption:=Datawell.ReplaceVariables(val);
    end;
  end
  else begin
    TBitBtn(ob).caption:=lab;
    TBitBtn(ob).hint:=val;
  end;
end;

procedure TFormCanvas.MenuPanicClick(Sender: TObject);
begin
  FormMain.MenuPanic.click;
end;

procedure TFormCanvas.Exit1Click(Sender: TObject);
begin
  close;
end;

procedure TFormCanvas.moveup1Click(Sender: TObject);
var
  ob: TControl;
  newt, newl, newh, neww, t, a: integer;
  moveU, moveD, moveL, moveR: boolean;
begin
  if PanelTools.height = 0 then exit;
  if selected < 1 then exit;
  moveU:=false;
  moveD:=false;
  moveL:=false;
  moveR:=false;
  ob:=GetControl(selected);
  newt:=ob.top;
  newl:=ob.left;
  newh:=ob.height;
  neww:=ob.width;
  a:=1;
  t:=TComponent(sender).tag;
  if (t > 100) and (t < 200) then begin
    a:=gridD;
    dec(t,100);
  end;
  case t of
    8: begin
         dec(newt,a);
         if newt < 0 then newt:=0;
         moveU:=true;
       end;
    2: begin
         inc(newt,a);
         if newt > PanelMain.height-ob.height then newt:=PanelMain.height-ob.height;
         moveD:=true;
       end;
    6: begin
         inc(newl,a);
         if newl > PanelMain.width-ob.width then newl:=PanelMain.width-ob.width;
         moveR:=true;
       end;
    4: begin
         dec(newl,a);
         if newl < 0 then newl:=0;
         moveL:=true;
       end;
    208: begin
           dec(newh,a);
           if newh < 8 then newh:=8;
           moveU:=true;
         end;
    202: begin
           inc(newh,a);
           if ob.top > PanelMain.height-newh then
             newh:=PanelMain.height-ob.top;
           moveD:=true;
         end;
    206: begin
           inc(neww,a);
           if ob.left > PanelMain.width-neww then
             neww:=PanelMain.width-ob.left;
           moveR:=true;
         end;
    204: begin
           dec(neww,a);
           if neww < 8 then neww:=8;
           moveL:=true;
         end;
  end;
  if a > 1 then begin
    if moveU then begin
      newt:=(newt div gridD) * gridD;
      if (ob.top - newt) > gridD then inc(newt,gridD);
    end
    else if moveD then newt:=(newt div 6) * 6
    else if moveL then begin
      newl:=(newl div gridD) * gridD;
      if (ob.left - newl) > gridD then inc(newl,gridD);
    end
    else if moveR then newl:=(newl div 6) * 6;
  end;
  ob.top:=newt;
  ob.left:=newl;
  ob.height:=newh;
  ob.width:=neww;
  UpdateSelection;
end;

procedure TFormCanvas.PanelMainMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if button = mbright then begin
    popitem:=0;
    PopupProperties.visible:=false;
    PopupLine1.visible:=false;
    PopupLine2.visible:=false;
    PopupColor.visible:=false;
    PopupColor.visible:=false;
    PopupFontSize.visible:=false;
    PopupFontColor.visible:=false;
    PopupAlignment.visible:=false;
    PopupDeleteObject.visible:=false;
    PopupBack.visible:=false;
    PopupFront.visible:=false;
    exit;
  end;
end;

procedure TFormCanvas.Delete1Click(Sender: TObject);
begin
  if selected < 1 then exit;
  if PanelTools.height = 0 then exit;
  GetControl(selected).hide;
  selected:=0;
  UpdateSelection;
  CheckRemaining;
  didchange:=true;
end;

procedure TFormCanvas.CheckRemaining;
var i, labs, buts: integer;
begin
  labs:=0; buts:=0;
  for i:=1 to 30 do begin
    if GetControl(i).visible then continue;
    inc(labs);
  end;
  for i:=101 to 110 do begin
    if GetControl(i).visible then continue;
    inc(buts);
  end;
  if labs > 0 then BtnLabel.enabled:=true else BtnLabel.enabled:=false;
  if buts > 0 then BtnButton.enabled:=true else BtnButton.enabled:=false;
end;

procedure TFormCanvas.PlaceLabel(x, y: integer);
var
  i: integer;
  lab: TLabel;
  didfind: boolean;
begin
  didfind:=false;
  for i:=1 to 30 do begin
    if GetControl(i).visible then continue;
    didfind:=true;
    break;
  end;
  if not didfind then exit;
  lab:=TLabel(GetControl(i));
  lab.hint:='';
  x:=(x div gridD) * gridD;
  y:=(y div gridD) * gridD;
  lab.top:=y;
  lab.left:=x;
  lab.height:=18;
  lab.width:=42;
  lab.caption:='label';
  lab.transparent:=false;
  lab.color:=clsilver;
  lab.font.size:=8;
  lab.font.color:=clblack;
  lab.alignment:=tacenter;
  lab.visible:=true;
  selected:=i;
end;

procedure TFormCanvas.PlaceButton(x, y: integer);
var
  i: integer;
  but: TBitBtn;
  didfind: boolean;
begin
  didfind:=false;
  for i:=101 to 110 do begin
    if GetControl(i).visible then continue;
    didfind:=true;
    break;
  end;
  if not didfind then exit;
  but:=TBitBtn(GetControl(i));
  but.hint:='';
  if PopupSnap.checked then begin
    x:=(x div gridD) * gridD;
    y:=(y div gridD) * gridD;
  end;
  but.top:=y;
  but.left:=x;
  but.height:=18;
  but.width:=54;
  but.caption:='button';
  but.font.size:=8;
  but.font.color:=clblack;
  but.visible:=true;
  selected:=i;
end;

procedure TFormCanvas.EditUnEdit1Click(Sender: TObject);
begin
  if PanelTools.height = 0 then PopupOpenEditor.click
  else BtnCloseEditor.click;
end;

procedure TFormCanvas.PopupBackClick(Sender: TObject);
begin
  case TComponent(sender).tag of
    -1: TControl(GetControl(popitem)).sendtoback;
     1: TControl(GetControl(selected)).bringtofront;
  end;
  didchange:=true;
end;

procedure TFormCanvas.PopupSnapClick(Sender: TObject);
begin
  PopupSnap.checked:=not PopupSnap.checked;
end;

procedure TFormCanvas.BtnVariablesMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i: integer;
begin
  if button <> mbleft then exit;
  for i:=1 to 30 do begin
    caps[i]:=TLabel(GetControl(i)).caption;
    TLabel(GetControl(i)).caption:=TLabel(GetControl(i)).hint;
  end;
  for i:=1 to 10 do begin
    caps[i+30]:=TButton(GetControl(i+100)).caption;
    TButton(GetControl(i+100)).caption:='';
  end;
end;

procedure TFormCanvas.BtnVariablesMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i: integer;
begin
  if button <> mbleft then exit;
  for i:=1 to 30 do TLabel(GetControl(i)).caption:=caps[i];
  for i:=1 to 10 do TLabel(GetControl(i+100)).caption:=caps[i+30];
end;

procedure TFormCanvas.MenuHideTitlebarClick(Sender: TObject);
begin
  MenuHideTitlebar.checked:=not MenuHideTitlebar.checked;
  if Paneltools.height = 0 then UpdateTitlebar;
  didchange:=true;
end;

procedure TFormCanvas.UpdateTitlebar;
begin
  if MenuHideTitlebar.checked then begin
    borderstyle:=bsnone;
    height:=height-22;
    width:=width-8;
  end
  else begin
    borderstyle:=bstoolwindow;
    height:=height+22;
    width:=width+8;
  end;
end;

procedure TFormCanvas.Properties1Click(Sender: TObject);
begin
  if selected < 1 then exit;
  DoProperties;
end;

procedure TFormCanvas.TimerTimer(Sender: TObject);
begin
  Timer.enabled:=false;
  selecting:=false;
  selx:=0; sely:=0;
end;

procedure TFormCanvas.MenuExportClick(Sender: TObject);
var
  adds: TStringList;
  PFile: TextFile;
  i: integer;
  work: string;
begin
  DialogSave.initialdir:=Datawell.GetDir(1);
  DialogSave.filename:='canvas';
  if not DialogSave.execute then abort;
  Datawell.SetDir(1,DialogSave.filename);
  SaveOptions;
  adds:=TStringList.create;
  adds.add('DO NOT EDIT THIS FILE!');
  adds.add(Datawell.version2);
  with Datawell.TableOptions3 do begin
    edit;
    fieldbyname('I12').asinteger:=top;
    fieldbyname('I13').asinteger:=left;
    fieldbyname('I14').asinteger:=height-PanelTools.height;
    fieldbyname('I15').asinteger:=width;
    fieldbyname('I16').asinteger:=PanelMain.color;
    fieldbyname('L19').asboolean:=MenuStayOnTop.checked;
    fieldbyname('L21').asboolean:=PopupSnap.checked;
    fieldbyname('L22').asboolean:=MenuHideTitlebar.checked;
    post;
    work:='FALSE'; if fieldbyname('L19').asboolean then work:='TRUE'; adds.add(work);
    work:='FALSE'; if fieldbyname('L21').asboolean then work:='TRUE'; adds.add(work);
    work:='FALSE'; if fieldbyname('L22').asboolean then work:='TRUE'; adds.add(work);
    adds.add(fieldbyname('S31').asstring);
    adds.add(inttostr(fieldbyname('I12').asinteger));
    adds.add(inttostr(fieldbyname('I13').asinteger));
    adds.add(inttostr(fieldbyname('I14').asinteger));
    adds.add(inttostr(fieldbyname('I15').asinteger));
    adds.add(inttostr(fieldbyname('I16').asinteger));
  end;
  with Datawell.TableOptions4 do begin
    adds.add(fieldbyname('S1').asstring);
    adds.add(fieldbyname('S2').asstring);
    adds.add(fieldbyname('S3').asstring);
    adds.add(fieldbyname('S4').asstring);
    adds.add(fieldbyname('S5').asstring);
    adds.add(fieldbyname('S6').asstring);
    adds.add(fieldbyname('S7').asstring);
    adds.add(fieldbyname('S8').asstring);
    adds.add(fieldbyname('S9').asstring);
    adds.add(fieldbyname('S10').asstring);
    adds.add(fieldbyname('S11').asstring);
    adds.add(fieldbyname('S12').asstring);
    adds.add(fieldbyname('S13').asstring);
    adds.add(fieldbyname('S14').asstring);
    adds.add(fieldbyname('S15').asstring);
    adds.add(fieldbyname('S16').asstring);
    adds.add(fieldbyname('S17').asstring);
    adds.add(fieldbyname('S18').asstring);
    adds.add(fieldbyname('S19').asstring);
    adds.add(fieldbyname('S20').asstring);
    adds.add(fieldbyname('S21').asstring);
    adds.add(fieldbyname('S22').asstring);
    adds.add(fieldbyname('S23').asstring);
    adds.add(fieldbyname('S24').asstring);
    adds.add(fieldbyname('S25').asstring);
    adds.add(fieldbyname('S26').asstring);
    adds.add(fieldbyname('S27').asstring);
    adds.add(fieldbyname('S28').asstring);
    adds.add(fieldbyname('S29').asstring);
    adds.add(fieldbyname('S30').asstring);
    adds.add(fieldbyname('S31').asstring);
    adds.add(fieldbyname('S32').asstring);
    adds.add(fieldbyname('S33').asstring);
    adds.add(fieldbyname('S34').asstring);
    adds.add(fieldbyname('S35').asstring);
    adds.add(fieldbyname('S36').asstring);
    adds.add(fieldbyname('S37').asstring);
    adds.add(fieldbyname('S38').asstring);
    adds.add(fieldbyname('S39').asstring);
  end;
  adds.add('<ENDCANVAS>');
  AssignFile(PFile,DialogSave.filename);
  Rewrite(PFile);
  for i:=0 to adds.count-1 do WriteLn(PFile,adds[i]);
  CloseFile(PFile);
  adds.free;
  didchange:=false;
  messagedlg('Export complete!',mtinformation,[mbok],0);
end;

procedure TFormCanvas.MenuImportClick(Sender: TObject);
var
  cver, version, loadfile: string;
  currentversion, fileversion: integer;
  lines: TStringList;
  bwork, frommain: boolean;
begin
  frommain:=(gfile <> '');
  if gfile = '' then begin
    if didchange then begin
      if messagedlg('The current canvas has change.  Overwrite with the imported one?',
        mtconfirmation,[mbyes,mbcancel],0) = mrcancel then exit;
    end;
    DialogOpen.initialdir:=Datawell.GetDir(1);
    if not DialogOpen.execute then exit;
    Datawell.SetDir(1,DialogOpen.filename);
    loadfile:=DialogOpen.filename;
  end
  else loadfile:=gfile;
  gfile:='';
  if PanelTools.height > 0 then BtnCloseEditor.click;
//check version
  lines:=TStringList.create;
  try
    if FileExists(loadfile) then
      lines.loadfromfile(loadfile);
    if lines.count < 1 then begin
      messagedlg('The file is corrupt',mtinformation,[mbok],0);
      exit;
    end;
    lines.delete(0);
    version:=lines[0];
  finally
    lines.free;
  end;
  version:=Datawell.subs(FormatSettings.DecimalSeparator,'',version);
  version:=Datawell.subs('.','',version);
  version:=Datawell.subs(',','',version);
  try fileversion:=strtoint(version);
    except on EConvertError do begin
      messagedlg('The file is corrupt',mtinformation,[mbok],0);
      exit;
    end;
  end;
  cver:=Datawell.version;
  cver:=Datawell.subs(FormatSettings.DecimalSeparator,'',cver);
  cver:=Datawell.subs('.','',cver);
  cver:=Datawell.subs(',','',cver);
  currentversion:=Datawell.toint(cver);
  while copy(version,length(version),1) = '0' do version:=copy(version,1,length(version)-1);
  if (fileversion > 6300) and (fileversion < 7600) then begin
    messagedlg('Beta files can''t be imported',mtinformation,[mbok],0);
    exit;
  end;
  if fileversion > currentversion then begin
    messagedlg('You need client version '+version+' to import that file',
      mtinformation,[mbok],0);
    exit;
  end;
  //Start import
  lines:=TStringList.create;
  try
    if fileExists(loadfile) then
      lines.loadfromfile(loadfile);
    lines.delete(0);
    lines.delete(0);
  //Parse information
    with Datawell.TableOptions3 do begin
      edit;
      if lines[0] = 'TRUE' then bwork:=true else bwork:=false;
      fieldbyname('L19').asboolean:=bwork;
      lines.delete(0);
      if lines[0] = 'TRUE' then bwork:=true else bwork:=false;
      fieldbyname('L21').asboolean:=bwork;
      lines.delete(0);
      if lines[0] = 'TRUE' then bwork:=true else bwork:=false;
      fieldbyname('L22').asboolean:=bwork;
      lines.delete(0);
      fieldbyname('S31').asstring:=lines[0];
      lines.delete(0);
      fieldbyname('I12').asinteger:=strtoint(lines[0]);
      lines.delete(0);
      fieldbyname('I13').asinteger:=strtoint(lines[0]);
      lines.delete(0);
      fieldbyname('I14').asinteger:=strtoint(lines[0]);
      lines.delete(0);
      fieldbyname('I15').asinteger:=strtoint(lines[0]);
      lines.delete(0);
      fieldbyname('I16').asinteger:=strtoint(lines[0]);
      lines.delete(0);
      post;
      if fieldbyname('L19').asboolean then formstyle:=fsstayontop else formstyle:=fsnormal;
      PopupSnap.checked:=fieldbyname('L21').asboolean;
      MenuHideTitlebar.checked:=fieldbyname('L22').asboolean;
      UpdateTitlebar;
      FormMain.UpdateWindowCaptions;
      top:=fieldbyname('I12').asinteger;
      left:=fieldbyname('I13').asinteger;
      height:=fieldbyname('I14').asinteger;
      width:=fieldbyname('I15').asinteger;
      PanelMain.color:=fieldbyname('I16').asinteger;
    end;
    with Datawell.TableOptions4 do begin
      edit;
      fieldbyname('S1').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S2').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S3').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S4').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S5').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S6').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S7').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S8').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S9').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S10').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S11').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S12').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S13').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S14').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S15').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S16').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S17').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S18').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S19').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S20').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S21').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S22').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S23').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S24').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S25').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S26').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S27').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S28').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S29').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S30').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S31').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S32').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S33').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S34').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S35').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S36').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S37').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S38').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S39').asstring:=lines[0]; lines.delete(0);
      fieldbyname('S40').asstring:=lines[0]; lines.delete(0);
      post;
    end;
  finally
    lines.free;
  end;
  LoadOptions;
  with FormMain do begin
    with Datawell.TableVariables do begin
      first;
      while not EOF do begin
        UpdateCanvasVariable('@'+fieldbyname('FVariable').asstring,fieldbyname('FValue').asstring);
        next;
      end;
    end;
    UpdateCanvasVariable('@HP',LabelHP.caption);
    UpdateCanvasVariable('@MAXHP',LabelHPMAX.caption);
    UpdateCanvasVariable('@SP',LabelSP.caption);
    UpdateCanvasVariable('@MAXSP',LabelSPMAX.caption);
    UpdateCanvasVariable('@GP1',LabelGP1.caption);
    UpdateCanvasVariable('@MAXGP1',LabelGP1MAX.caption);
    UpdateCanvasVariable('@GP2',LabelGP2.caption);
    UpdateCanvasVariable('@MAXGP2',LabelGP2MAX.caption);
    UpdateCanvasVariable('@ENEMY',inttostr(GaugeEnemy.progress));
    UpdateCanvasVariable('@ENAME',GetEName);
    UpdateCanvasVariable('@GLINE1',Datawell.gline1);
    UpdateCanvasVariable('@GLINE2',Datawell.gline2);
    UpdateCanvasVariable('@CAPTION',caption);
    UpdateCanvasVariable('@AA',scripts.GetVarValueAsString('AA'));
    UpdateCanvasVariable('@BB',scripts.GetVarValueAsString('BB'));
    UpdateCanvasVariable('@CC',scripts.GetVarValueAsString('CC'));
    UpdateCanvasVariable('@DD',scripts.GetVarValueAsString('DD'));
    UpdateCanvasVariable('@EE',scripts.GetVarValueAsString('EE'));
    UpdateCanvasVariable('@FF',scripts.GetVarValueAsString('FF'));
  end;
  if frommain then FormMain.show;
end;

procedure TFormCanvas.ResetCanvas1Click(Sender: TObject);
begin
  if messagedlg('Are you sure?  This cannot be undone',
    mtconfirmation,[mbyes,mbcancel],0) = mrcancel then exit;
  with Datawell.TableOptions3 do begin
    edit;
    fieldbyname('L19').asboolean:=false;
    fieldbyname('L21').asboolean:=true;
    fieldbyname('L22').asboolean:=false;
    fieldbyname('S31').asstring:='';
    fieldbyname('I12').asinteger:=0;
    fieldbyname('I13').asinteger:=0;
    fieldbyname('I14').asinteger:=300;
    fieldbyname('I15').asinteger:=350;
    fieldbyname('I16').asinteger:=clteal;
    post;
    if fieldbyname('L19').asboolean then formstyle:=fsstayontop else formstyle:=fsnormal;
    PopupSnap.checked:=fieldbyname('L21').asboolean;
    MenuHideTitlebar.checked:=fieldbyname('L22').asboolean;
    UpdateTitlebar;
    FormMain.UpdateWindowCaptions;
    top:=fieldbyname('I12').asinteger;
    left:=fieldbyname('I13').asinteger;
    height:=fieldbyname('I14').asinteger;
    width:=fieldbyname('I15').asinteger;
    PanelMain.color:=fieldbyname('I16').asinteger;
  end;
  with Datawell.TableOptions4 do begin
    edit;
    fieldbyname('S1').asstring:='';
    fieldbyname('S2').asstring:='';
    fieldbyname('S3').asstring:='';
    fieldbyname('S4').asstring:='';
    fieldbyname('S5').asstring:='';
    fieldbyname('S6').asstring:='';
    fieldbyname('S7').asstring:='';
    fieldbyname('S8').asstring:='';
    fieldbyname('S9').asstring:='';
    fieldbyname('S10').asstring:='';
    fieldbyname('S11').asstring:='';
    fieldbyname('S12').asstring:='';
    fieldbyname('S13').asstring:='';
    fieldbyname('S14').asstring:='';
    fieldbyname('S15').asstring:='';
    fieldbyname('S16').asstring:='';
    fieldbyname('S17').asstring:='';
    fieldbyname('S18').asstring:='';
    fieldbyname('S19').asstring:='';
    fieldbyname('S20').asstring:='';
    fieldbyname('S21').asstring:='';
    fieldbyname('S22').asstring:='';
    fieldbyname('S23').asstring:='';
    fieldbyname('S24').asstring:='';
    fieldbyname('S25').asstring:='';
    fieldbyname('S26').asstring:='';
    fieldbyname('S27').asstring:='';
    fieldbyname('S28').asstring:='';
    fieldbyname('S29').asstring:='';
    fieldbyname('S30').asstring:='';
    fieldbyname('S31').asstring:='';
    fieldbyname('S32').asstring:='';
    fieldbyname('S33').asstring:='';
    fieldbyname('S34').asstring:='';
    fieldbyname('S35').asstring:='';
    fieldbyname('S36').asstring:='';
    fieldbyname('S37').asstring:='';
    fieldbyname('S38').asstring:='';
    fieldbyname('S39').asstring:='';
    fieldbyname('S40').asstring:='';
    post;
  end;
  Label1.hide;
  Label2.hide;
  Label3.hide;
  Label4.hide;
  Label5.hide;
  Label6.hide;
  Label7.hide;
  Label8.hide;
  Label9.hide;
  Label10.hide;
  Label11.hide;
  Label12.hide;
  Label13.hide;
  Label14.hide;
  Label15.hide;
  Label16.hide;
  Label17.hide;
  Label18.hide;
  Label19.hide;
  Label20.hide;
  Label21.hide;
  Label22.hide;
  Label23.hide;
  Label24.hide;
  Label25.hide;
  Label26.hide;
  Label27.hide;
  Label28.hide;
  Label29.hide;
  Label30.hide;
  Btn1.hide;
  Btn2.hide;
  Btn3.hide;
  Btn4.hide;
  Btn5.hide;
  Btn6.hide;
  Btn7.hide;
  Btn8.hide;
  Btn9.hide;
  Btn10.hide;
  BtnCloseEditorClick(nil);
  LoadOptions;
end;

end.
